package view;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.event.TableModelEvent;
import javax.swing.table.TableColumnModel;

public class HeaderListener<T> extends MouseAdapter {
	SortedTable<T> table = null;
	boolean asending = true;

	public HeaderListener(SortedTable<T> table) {
		this.table = table;
	}

	public void mouseClicked(MouseEvent e) {
		TableColumnModel colModel = table.getColumnModel();
		int columnModelIndex = colModel.getColumnIndexAtX(e.getX());
		table.getTableHeader().repaint();
		table.getModel().order(columnModelIndex, asending);
		asending = !asending;
		table.tableChanged(new TableModelEvent(table.getModel()));
		table.repaint();
	}
}
